package com.hd.controller.sqlexcel;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hd.controller.base.BaseController;
import com.hd.entity.sqlexcel.SqlReportType;
import com.hd.service.sqlexcel.SqlReportTypeService;
import com.hd.util.result.PageInfo;

/**
* 报表类型
*/
@RequestMapping("sqlReportType")
@Controller
public class SqlReportTypeController extends BaseController {

    @Autowired
    private SqlReportTypeService sqlReportTypeService;
    /**
     * 主页
     * @return
     */
    @RequestMapping("manager")
    public String manager() {
        return "jsp/report/sqlReportType/sqlReportTypeList";
    }
    /**
     * 列表
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
    @RequestMapping(value="/dataGrid",method=RequestMethod.POST)
    @ResponseBody
    public Object dataGrid(SqlReportType sqlReportType, Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        Map<String,Object>condition=new HashMap<String,Object>();
        pageInfo.setCondition(condition);
        sqlReportTypeService.selectDataGrid(pageInfo);
        return pageInfo;
    }

    /**
     * 添加页
     * @return
     */
    @RequestMapping("/addPage")
    public String addPage() {
        return "jsp/report/sqlReportType/sqlReportTypeAdd";
    }

    /**
     * 添加
     * @param sqlReportType
     * @return
     */
    @RequestMapping(value="/add",method=RequestMethod.POST)
    @ResponseBody
    public Object add(SqlReportType sqlReportType) {
        sqlReportTypeService.save(sqlReportType);
        return renderSuccess("添加成功！");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public Object delete(@PathVariable("id") String id) {
        //sqlReportTypeService.delete(id);
        sqlReportTypeService.updateStatus(0,id);
        return renderSuccess("删除成功！");
    }
    /**
     * 编辑页
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/editPage/{id}")
	public String editPage(Model model, @PathVariable("id")String id) {
	 SqlReportType sqlReportType = sqlReportTypeService.get(id);
        model.addAttribute("sqlReportType", sqlReportType);
        return "jsp/report/sqlReportType/sqlReportTypeEdit";
    }

    /**
     * 查看页
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/viewPage/{id}")
    public String viewPage(Model model, @PathVariable("id") String id) {
        SqlReportType sqlReportType = sqlReportTypeService.get(id);
        model.addAttribute("sqlReportType", sqlReportType);
        return "jsp/report/sqlReportType/sqlReportTypeView";
    }
    /**
     * 编辑
     * @param sqlReportType
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ResponseBody
    public Object edit(SqlReportType sqlReportType) {
        sqlReportTypeService.update(sqlReportType);
        return renderSuccess("编辑成功！");
    }


}
